import numpy as np
import pandas as pd
import pyecharts
from pyecharts import Bar
from pyecharts import Pie


class ChipotleAna:

    path = 'C:/Users/ASUS/chipotle.csv'

    def __init__(self):

        self.df = pd.read_csv(self.path, sep='\t')

    def echarts_bar(self, series, bar_name='test', name='test_name'):

        bar = pyecharts.Bar(bar_name)

        asix0 = series.index

        asix1 = series.values.ravel()

        bar.add(name, asix0, asix1, is_label_show=True, is_datazoom_show=True)

        return bar

    def how_many_are_sold_per_item(self):  # 每个商品卖了多少件

        count_info = self.df.groupby('item_name').sum()

        count_info = count_info.drop('order_id', axis=1)

        return count_info

    def bar_how_many_are_sold_per_item(self):

        return self.echarts_bar(self.how_many_are_sold_per_item(), bar_name='每种商品卖出个数')

    def how_much_are_sold_per_item(self):  # 每个商品卖了多少钱

        x = self.df.quantity * (self.df.item_price.str.replace('$', '').astype('float64'))

        df1 = self.df.copy()

        df1['price'] = round(x, 2)

        df1 = df1.groupby('item_name').sum()

        return round(df1['price'], 2)

    def bar_how_much_are_sold_per_item(self):

        return self.echarts_bar(self.how_much_are_sold_per_item(), bar_name='每种商品总收入')

    def Nombre_de_ventes_par_type_de_produit(self):

        info = self.df.item_name.value_counts()

        x = info.index

        y = info.values.ravel()

        bar_4 = pyecharts.Bar('每种商品的销售个数')

        bar_4.add('数量', x, y)

        return bar_4

    def The_proportion_of_each_commodity_in_the_total_amount(self):#每种商品销售金额在流水总额中所占的比例

        item_name =  self.df.item_name.str.replace(" ", "_")

        item_name2 = self.df[item_name == "Chicken_Bowl"].choice_description.value_counts()

        name = []

        for i in item_name2.index:

            a = i.replace("[", "").replace("]", "").replace(",", "")

            name.append(a)

        shuliang = []

        for i in item_name2:

            shuliang.append(i)

        pie = Pie('饼图', background_color='white')

        pie.add('', name, shuliang)

        return pie

    def Montant_par_ordre(self):#销售金额

        produit_name = self.df.item_name.ravel()

        produit_quantites = self.df.quantity.ravel()

        item_price = self.df.item_price



        bar = pyecharts.Bar("销售个数", "2018-4-21", title_color='blue', width=1400, height=700, background_color='white')

        bar.add("销售个数", produit_name, produit_quantites, legend_text_color='red', is_datazoom_show=True)

        # bar.add("销售金额", produit_name, item_price, legend_text_color='blue')

        return bar








































































